*******************************************************************************************
*******************************************************************************************
*********  Preparation to Figure 3 ***********
*******************************************************************************************
*******************************************************************************************
frame create BARGAINspace
frame change BARGAINspace

use  "$rootfolder\Data\2-8-full-factorial-design.dta", clear


* create a matrix of 256 combination which also identifies the cards that are actually selected and their block number (so the subset selected can be distinguished by the full 256 factorial design)
append using "$rootfolder\Data\8-fractional-block-design.dta"
egen same_cards = group(a b c d e f g h)
sort same_cards sample
egen tag= tag(same_cards)
drop if tag==0

* check the scalars in memory: the  coefficients from the ranked ordered logit models are needed
scalar list 

* prepare the binary attributes
foreach var of varlist a-h {
replace `var'=0 if `var'==-1
}

* generate a unique and name for the cards based on its value so that sorting is univoc
egen cardname = concat(a b c d e f g h)

* sort the existing cards and number the missing list of cards (from orthogonal design) from card=66 onwards - remember that card status quo ==99 and get ranmed to 65
sort number_continu cardname
replace number_continuous = 65 if number_continuous==99
gen n = _n
replace number_continuous= n if number_continuous==.
drop n

* calculate the utility for all possible 256 combinations
capture drop P_uvalue256 I_uvalue256
gen P_uvalue256 = _bARa*a + _bARb*b +  _bARc*c + _bARd*d + _bARe*e + _bARf*f +  _bARg*g + _bARh*h

gen I_uvalue256 = _bHEa*a + _bHEb*b +  _bHEc*c + _bHEd*d + _bHEe*e + _bHEf*f +  _bHEg*g + _bHEh*h

